package com.polaris.live.utils.livehelper

import android.content.Context
import android.os.Looper
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.polaris.live.databinding.LivePlayViewBinding
import im.zego.zegoexpress.constants.ZegoPlayerState
import im.zego.zegoexpress.constants.ZegoRemoteDeviceState
import im.zego.zegoexpress.constants.ZegoStreamResourceMode
import im.zego.zegoexpress.entity.ZegoPlayStreamQuality
import org.json.JSONObject

/**
 * LivePlayView  播放直播流控件
 * @author Created by 天晴 on 2024/1/3 10:23
 * @since 1.0.0
 **/
class LivePlayView(context: Context, attributeSet: AttributeSet) :
    RelativeLayout(context, attributeSet), LiveListener {
    private val mBinding = LivePlayViewBinding.inflate(LayoutInflater.from(context), this)


    private var streamId: String? = null


    /**
     * 开始播放
     */
    fun startLive(
        streamId: String,
        isMute: Boolean,
        playMode: ZegoStreamResourceMode = ZegoStreamResourceMode.ONLY_L3,
    ) {
        check(Looper.myLooper() == Looper.getMainLooper()) {
            "The stream must be played on the main thread."
        }
        this.streamId = streamId
    }

    /**
     * 停止播放
     */
    fun stopLive() {
        check(Looper.myLooper() == Looper.getMainLooper()) {
            "The stream must be played on the main thread."
        }
        streamId?.let {
        }
    }

    fun release() {
        stopLive()
    }

    override fun start() {  //正常开始播放
    }

    override fun stop() {  //播放关闭

    }

    override fun onPlayerStateUpdate(
        state: ZegoPlayerState?,
        errorCode: Int,
        extendedData: JSONObject?
    ) {
    }

    override fun onRemoteSpeakerStateUpdate(state: ZegoRemoteDeviceState) {
    }

    override fun onPlayerQualityUpdate(quality: ZegoPlayStreamQuality) {
    }


}